<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-tab layui-tab-brief">
      <ul class="layui-tab-title">
        <li class="layui-this">接口设置</li>
      </ul>
      <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
          <div class="layui-row"></div>
          <table id="XxPay_Mgr_Pri_IfType_dataAll" lay-filter="XxPay_Mgr_Pri_IfType_dataAll"></table>
        </div>
        <div class="layui-form">
          <button class="layui-hide xxpayYesBtn" lay-submit lay-filter="priMchIfTypeSave">保存</button>
        </div>

      </div>
    </div>
  </div>
</div>

<script>
  layui.use(['admin', 'table', 'util'], function(){
    var $ = layui.$
            ,admin = layui.admin
            ,table = layui.table
            ,element = layui.element
            ,form = layui.form
            ,view = layui.view;

    element.render('breadcrumb', 'breadcrumb');
    var mchId = layui.view.getOpenParams('mchId');
    var tplIfTypeType = function(d){
        if(d.IfTypeType == 1) {
            return '收款';
        }else if(d.IfTypeType == 2) {
            return '充值';
        }else {
            return '';
        }
    };
    table.render({
      elem: '#XxPay_Mgr_Pri_IfType_dataAll'
      ,url: layui.setter.baseUrl + '/mch_info/getPriMchSupportIfType' //列表接口
      ,where: {
          access_token: layui.data(layui.setter.tableName).access_token,
          mchId : mchId
      }
      ,id: 'tableReloadByPriIfType'
      ,page: true
      ,cols: [[
        {type: 'checkbox', fixed: 'left'}
        ,{field:'ifTypeCode', title: '接口类型代码'}
        ,{field:'ifTypeName',  title: '接口类型名称'}
      ]]
        ,skin: 'line'
    });

    form.on('submit(priMchIfTypeSave)', function(data) {

        var updateIfType = "";

        var checkData = table.checkStatus('tableReloadByPriIfType');
        $.each(checkData.data, function(){
            updateIfType += (this.ifTypeCode + ",");
        });
        if(updateIfType.length > 0){
            updateIfType = updateIfType.substring(0, updateIfType.length - 1);
        }

        admin.req({
            type: "POST",
            url: layui.setter.baseUrl + '/mch_info/updatePriMchSupportIfType',
            data: {mchId: mchId, updateIfType: updateIfType},
            success: function(res){
                if(res.code == 0) {
                    layer.alert(res.msg, {title: "提示"}, function(index){

                        layer.closeAll(); //关闭所有弹层
                        layui.table.reload('tableReload'); //调用业务弹层外表格重新加载
                    });
                }
            }
        });

    });

    // 渲染表单
    form.render();
  });
</script>